<?php
namespace App\Api\Controllers;
use AlibabaCloud\Live\Live;
use Common\ApiController;
use Common\Common;
use Common\Models\Article;
use Common\Models\ArticleCategory;
use Common\Models\ArticleFaquan;
use Common\Models\ArticleFaquanCate;
use Services\Api\LiveServices;
use Services\Api\TurnServices;

class LiveController extends ApiController
{
	public function initialize()
	{
		parent::initialize();
	}

    /**
     * 获取商家分类
     */
	public function categoryAction(){
        if(!isset($this->params['type']) || empty($this->params['type'])){
            $this->fail(-1,"类型不能为空");
        }
        $this->params['type']=1;
        if(!isset($this->params['pid'])){
            $this->fail(-1,"上级id不能为空");
        }
        $LiveServices = new LiveServices();
        $liveServices = $LiveServices->category((int)$this->params['type'],(int)$this->params['pid']);
        $this->ok($liveServices);
    }


    /**
     * 获取列表
     */
    public function get_listAction(){
        if(!isset($this->params['cate_id']) || empty($this->params['cate_id'])){
            $this->params['cate_id'] = 40786;
        }
        if(!isset($this->params['page']) || empty($this->params['page'])){
            $this->params['page'] = 1;
        }
        if(!isset($this->params['page_size']) || empty($this->params['page_size'])){
            $this->params['page_size'] = 20;
        }
        if(!isset($this->params['longitude']) || empty($this->params['longitude'])){
            $this->params['longitude'] = '109.73159819782256';
        }
        if(!isset($this->params['latitude']) || empty($this->params['latitude'])){
            $this->params['latitude'] = '30.609138775242243';
        }
        $LiveServices = new LiveServices();
        $responseResult = $LiveServices->get_list($this->user_info,$this->params);
        if($responseResult['status']){
            $this->ok($responseResult['data']);
        }
        $this->fail(-1,$responseResult['msg']);
    }


    /**
     * 美团获取城市分类列表
     */
    public function cityCateAction(){
        $LiveServices = new LiveServices();
        $responseResult = $LiveServices->cityCate($this->user_info,$this->params);
        $this->ok($responseResult);
    }


    /**
     * 美团团购列表
     */
    public function searchDealsAction(){
        if(!isset($this->params['cat0Id']) || empty($this->params['cat0Id'])){
            $this->fail(-1,'一级分类不能为空');
        }
        if(!isset($this->params['longitude']) || empty($this->params['longitude'])){
            $this->params['longitude'] = '106.57867659542845';
        }

        if(!isset($this->params['latitude']) || empty($this->params['latitude'])){
            $this->params['latitude'] = '29.562158340449272';
        }

        if(!isset($this->params['dealType']) || empty($this->params['dealType'])){
            $this->params['dealType'] = '';
        }

        if(!isset($this->params['sortType']) || empty($this->params['sortType'])){
            $this->params['sortType'] = '';
        }

        if(!isset($this->params['radii']) || empty($this->params['radii'])){
            $this->params['radii'] = '';
        }

        if(!isset($this->params['cat1Ids']) || empty($this->params['cat1Ids'])){
            $this->params['cat1Ids'] = '';
        }

        if(!isset($this->params['keywords']) || empty($this->params['keywords'])){
            $this->params['keywords'] = '';
        }

        if(!isset($this->params['cityId']) || empty($this->params['cityId'])){
            $this->params['cityId'] = '';
        }

        if(!isset($this->params['page']) || empty($this->params['page'])){
            $this->params['page'] = 1;
        }

        if(!isset($this->params['pageSize']) || empty($this->params['pageSize'])){
            $this->params['pageSize'] = 50;
        }
        $LiveServices = new LiveServices();
        $response = $LiveServices->searchDeals(0,$this->params['cat0Id'],$this->params['longitude'],$this->params['latitude'],$this->params['page'],$this->params['pageSize'],$this->params['dealType'],$this->params['sortType'],$this->params['radii'],$this->params['cat1Ids'],$this->params['keywords'],$this->params['cityId']);
        $this->ok($response);
    }



    /**
     * 团购详情
     */
    public function shopDetailAction()
    {
        if(!isset($this->params['cat0Id']) || empty($this->params['cat0Id'])){

        }

        if(!isset($this->params['longitude']) || empty($this->params['longitude'])){
            $this->params['longitude'] = '106.57867659542845';
        }

        if(!isset($this->params['latitude']) || empty($this->params['latitude'])){
            $this->params['latitude'] = '29.562158340449272';
        }

        if(!isset($this->params['shopIds']) || empty($this->params['shopIds'])){
            $this->fail(-1,'店铺ID不能为空');
        }

        $LiveServices = new LiveServices();
        $response = $LiveServices->shopDetail($this->params);
        $this->ok($response);
    }


}
